import request from '@/http/request'

// 创建支付宝订单
export function createAlipayOrder(data) {
  return request({
    url: '/users/api/alipay/create_order',
    method: 'post',
    data
  })
}

// 查询订单状态
export function queryAlipayOrder(orderNumber) {
  return request({
    url: '/users/api/alipay/query_order',
    method: 'get',
    params: { order_number: orderNumber }
  })
}

// 生成订单号
export function generateOrderNumber() {
  const now = new Date()
  const year = now.getFullYear()
  const month = String(now.getMonth() + 1).padStart(2, '0')
  const day = String(now.getDate()).padStart(2, '0')
  const hours = String(now.getHours()).padStart(2, '0')
  const minutes = String(now.getMinutes()).padStart(2, '0')
  const seconds = String(now.getSeconds()).padStart(2, '0')
  const random = Math.floor(Math.random() * 1000).toString().padStart(3, '0')
  
  return `ORDER${year}${month}${day}${hours}${minutes}${seconds}${random}`
}